Introduction to the Gaming Ecosystem

Introduction#

Gaming has become a global market. With technological advancements such as 3D graphics, virtual reality, improved hardware, etc., the gaming industry has become a major part of the entertainment industry. Today, games are played by players of all ages on different platforms. Game development is a complicated and difficult process due to the varying nature and impact of the laws of physics when simulating real-world scenarios. (For example, if a bullet is fired to hit an object at a distance, what motion should it follow, taking into account gravity and air friction?) Online multiplayer games are popular and difficult to manage due to gaming mechanics, graphics design, and APIs that support real-time performance and compatibility with different gaming consoles. The following table shows some of the major factors involved in the game development process:

Factors Affecting Game Development

Factor

Description

Game logic

The rules and principles that the game follows

Rendering

Complexity involved with the graphics used in different game scenes

Data synchronization

The frequency with which the data in a game is synced, depending on whether the game is time sensitive, played online or offline, or other considerations

Platform abstraction

Managing dependencies to support multiple platforms like mobile, PC, PlayStation 5, Xbox, etc.

Development budget

Budgetary decisions, depending on whether the game is a project of a large publisher or an independent developer

To realize the inherent challenges, let's learn about the essential concepts involved in the frontend and backend development processes.

Note: The frontend includes the client-side application that the user interacts with. These include game visuals, player models, game controls, etc. The backend is concerned with the technologies on the server-side such as databases, hardware infrastructure, network components, APIs, and so on.

Time-based classification of game#

Games can be classified according to different factors or requirements. We divide games into the following three categories based on their time-sensitive nature.

  • Time independent: Offline games that involve adventure, puzzle solving, and storytelling like Angry Birds, PikPok, and more.

  • Fixed intervals: Games played in turn, such as chess, shogi, Go, and other strategy board games.

  • Near real time: Online games that involve real-time interaction, such as Call of Duty (COD).

The intricacy of near real-time games is the prime focus of this chapter. Let's analyze the components involved in building a gaming system.

Gaming ecosystem#

A gaming ecosystem involves managing its own unique components apart from handling other sophisticated services like in-app purchases, advertisements, and more. Additionally, games are computationally quite expensive due to the following reasons:

  • Complex game logic: Let's take a relatively simple example of chess to understand the complexity involved in developing games. In a game of chess, there are about 104310^{43} — 105010^{50} possible situations that follow the rules of the game. Now extend this analysis to get an idea of the complexities associated with a real-time multiplayer game in which many actions are performed in many permissible combinations with a great amount of data to reflect a state.

  • Rendering 3D graphics: Most video games employ complex 3D environments to simulate virtual reality, which requires a lot of processing power. Typically, additional hardware (like a GPU) is required for fast frame generation and a smooth user experience.

To address these challenges, game creators often turn to third-party tools and solutions that meet their needs rather than developing from scratch.

Game engines#

A game engine is a framework for developing games that performs a central role in game development and provides a collaborative environment for developers to manage code, graphics, music, etc. In most modern video games, everything is a 3D model with its own characteristics and physical properties, which create a complex graph of interdependencies. Let's take a simple example of building a character as shown below:

3D object model and associated characteristics
3D object model and associated characteristics

Note: The image above shows the 3D object model for the character Deadpool. We can see the actual character on the left. In the bottom right, we can also see that it is made up of many small triangles that create a mesh for the object's skin (commonly called wireframe.) In the upper right corner, we can also see the properties associated with it.

Creating a wireframe, as shown above, may take 32 to 42 work hours for a 3D architect. In contrast, a full model that can perform movement requires wriggling, which requires extra work and depends on the number of vertices and the level of detail added to the skeleton. After that, the actual animation is created on this skeleton, which takes even more time and effort than the steps done before and depends heavily on how smooth the animation is and the number of dimensions associated with that animation.

In addition to the above, games also have to deal with special effects, AI, physics, and more, which require a lot of code to produce specific scenes. While we can create and manage our own codebase to manage all these requirements, developers often prefer to use existing public or private options. These existing resources are usually well tested for memory management, performance optimization, and much more. Now that we understand the role and responsibility of game engines, let’s learn about other factors involved in the gaming ecosystem.

Smooth playing experience#

A seamless gaming experience is influenced by various variables. Let's learn about some of the most important ones given below:

  • Device specifications: Gaming experience largely depends on the minimum capabilities of the device. For example, the number of threads it can handle, how much throughput the installed GPU has, the screen resolution and refresh rate, etc., determine the computing power required to handle factors such as depth of field, texture resolution, static and dynamic lighting effects, the responsive radius, etc.

  • Game engine: The technology and optimization methods adopted by the game engine are one of the main factors that affect the players' gaming experience. For instance, how efficiently the game engine manages memory, the number of draw calls, and other computations depend on the techniques used in the game engine. If a game engine has some performance limitations, we may not be able to extract more performance from our service.

Note:  A draw call is a request to execute a function to draw one or more geometric shapes on the screen.

  • Network and synchronization: The network distance required for clients to transmit data and how the data is being synchronized between different players affect the overall game experience, especially when gameplay demands communication in near real time.

While hardware and code implementation directly affect the gameplay, other elements, such as network performance, play a vital role in the overall gaming experience. Let's discuss those details in the next section.

Network and state synchronization#

The game state is the description of every object in the game at a given point in time. Different players can have different game states for their game session because, in multiplayer games, players change their local version of the game state. Therefore, it is important to synchronize each player's game state with everyone else in that game. The methodology used to synchronize the client and server states is also important for smooth and lag-free gaming. The following are some techniques that we use to smooth play frames:

  • Buffering and prefetching: Displaying frames as soon as they are received by the remote players can cause glitching and jittering due to network conditions. We can buffer game data on the client side for a very short span of time before showing it to the player. This allows for a fluid display of action and movement.

  • Exchanging modified states: Sharing only the state of modified objects while keeping the rest in their default state reduces bandwidth utilization, latency, and rendering lag.

  • Client move prediction: Most game engines support predictive algorithms that predict the actions a player is likely to take in a given situation. The prediction approach is used to guess the next state and play smooth player motion even if player input is not received in time.

  • Lag compensation: It’s likely that the game scene will have a small change between the time the player sends the command and the server receiving the command. Lag compensation is a technique primarily used on authoritative servers (discussed later in this lesson) that allows the server to look at past scenes when the client performed an action, and take the appropriate action from the player's perspective when the server receives that action from the client.

Server side lag compensation
Server side lag compensation

The illustration above shows that the client and server sides can achieve the same game state due to lag compensation.

Quiz

Question

What is the difference between client move prediction and lag compensation?

Hide Answer

Both client move prediction and lag compensation are techniques used to address issues caused by delays that occur while receiving information sent by the client to the server. Their main difference is that in client-move prediction, the server anticipates the state of high-latency clients and sends that information to low-latency clients to improve the user experience and smooth gameplay.

In contrast, lag compensation is a technique that improves service accuracy by viewing the game state of the clients when an action was performed rather than when that action is received on the server side. Each command from the client arrives at the server with some delay. This delay can lead to inaccuracy in the state maintained by the server. To avoid this, the client sends a timestamp along with the command to the server. The server uses this timestamp to go into the past and reconstruct the same client’s state on the server before executing the command. This allows the server to minimize the impact of state changes introduced during data transfer from the client to the server.

Deployment policy#

A deployment policy defines how different components are configured to communicate with each other and achieve assigned goals. Here, we’ll discuss game deployment policy in terms of game state management. The following sections are the two popular approaches that we can take to synchronize game states.

Authoritative server#

The authoritative server style is a method where the game state is only managed by the server. The authoritative server maintains a simulation of the game, keeping track of all the player instances and state synchronization, and players send their moves or actions to the server to update their state.

Authoritative style client-server communication
Authoritative style client-server communication

The authoritative server style is scalable as we can add more servers with the increasing number of users. However, each server can host a single gameplay with a limited number of players. It’s also an effective approach to safeguard the game states from client-side hacks and cheats. Moreover, this type of synchronization architecture can support features like lag compensation, client-side prediction, and rollbacks.

Distributed authority#

Distributed authority (also called networked multiplayer) is an approach where the server only maintains a game session and keeps players connected. On the other hand, the players' game instances are responsible for updating the state of objects they own. By using peer-to-peer synchronization, the game state is gradually updated for all players. When the game's original organizer leaves, this design allows host migration and may be set up to handle basic data validation logic and cheat protection.

Networked multiplayer approach
Networked multiplayer approach

This approach works best for games with discrete game states that can be easily synchronized as, for example, in a turn-based game like chess, in which it scales at a low cost. However, it is much harder to synchronize the state after each frame for games with continuous game state updates. Also, as the number of players increases, we need to share O(n2)O(n^2) states, where nn is the number of players, which increases the network load.

This lesson discussed various aspects of a gaming ecosystem, including its functional logic, graphic rendering, state synchronization, and deployment techniques. We will use this background information in the next lesson to design a gaming API.

Requirements of the Gaming API

Gaming API Design Decisions